package com.example.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAspect {

    @Before("execution(public int com.example.impl.CalcServiceImpl.*(..))")
    public void beforeNotify(JoinPoint point){
        System.out.println("@Before  =================");
    }

    @After("execution(public int com.example.impl.CalcServiceImpl.*(..))")
    public void afterNotify(){
        System.out.println("@After =================");
    }

    @AfterReturning("execution(public int com.example.impl.CalcServiceImpl.*(..))")
    public void afterReturningNotify(){
        System.out.println("@AfterReturning   ==========================");
    }

    @AfterThrowing("execution(public int com.example.impl.CalcServiceImpl.*(..))")
    public void afterThrowingNotify(){
        System.out.println("@AfterThrowing   ==========================");
    }

    @Around("execution(public int com.example.impl.CalcServiceImpl.*(..))")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object retVal = null;
        System.out.println("around before========================");
        retVal = proceedingJoinPoint.proceed();
        System.out.println("around after========================");
        return retVal;
    }
}
